<?php 
class kdtrace_xiaobao extends Controller {
	
	function track( $tracknum , $lang = "en"){
		set_time_limit(60);
		$trackmode = 0;
		if($lang=="ch"){$langset = "CN";} else {$langset = "EN";};
		$curl = $this->instance('curl');

		$url = "http://api.sao.cn/track?mailNo=" . $tracknum . "&timeout=10&type=json&lang=" . $langset;
		$result = $curl->getRequest($url);
		
		$rtndata = array('tracknum'=>$tracknum,'header'=>array(),'err'=>array(),'eventList'=>array());
		$result = json_decode($result);
		$qstatus = $result['qstatus'];
		
		if( $qstatus==0 || $qstatus>90 || $result['mstatus']==0 ){
			if($qstatus==99){
				$trackmode = 1;
			}else{
				$rtndata['err']['errcode'] = '1';
				return $rtndata;
			}
		}
		if($trackmode==1){
			$url = "http://www.17track.net/r/handlertrack.ashx?callback=jQuery11&num=".$tracknum."&pt=0&cm=0&cc=0&_=".time();
			$result = $curl->getRequest($url);
			
		}
		$rtndata['err']['errcode'] = '0';
		
		
		return $rtndata;
	}
	
}

?>